$(document).ready(function () {
    /*
    $('.tab-content div:first-child').addClass("active");
    $('.nav-pills li:first-child').addClass('active');
    $('.nav').tab();
    */

    $('.datepicker').datepicker({
        nextText: "",
        prevText: "",
        dateFormat: 'dd.mm.yy'
    });

    // $('textarea[data-toggle=wysihtml5]').wysihtml5();

    $('a[data-toggle="tab"]').on('shown', function (e) {
        //e.target; // activated tab
        //e.relatedTarget; // previous tab
        var scrollmem = $('body').scrollTop();
        window.location = e.target;
        $('html,body').scrollTop(scrollmem);
        //window.history.pushState('page2', 'Title', e.target);
    })

    /**/
    // fix sub nav on scroll
    var $win = $(window)
      , $nav = $('.page-header')
      , navTop = $('.page-header').length && $('.page-header').offset().top - 50
      , isFixed = 0

    processScroll()

    // hack sad times - holdover until rewrite for 2.1
    $nav.on('click', function () {
        if (!isFixed) setTimeout(function () { $win.scrollTop($win.scrollTop() - 40) }, 10)
    })

    $win.on('scroll', processScroll)

    function processScroll() {
        var i, scrollTop = $win.scrollTop()
        if (scrollTop >= navTop && !isFixed) {
            isFixed = 1
            $nav.addClass('page-header-fixed')
        } else if (scrollTop <= navTop && isFixed) {
            isFixed = 0
            $nav.removeClass('page-header-fixed')
        }
    }

});

function getE(name) {
    if (document.getElementById)
        var elem = document.getElementById(name);
    else if (document.all)
        var elem = document.all[name];
    else if (document.layers)
        var elem = document.layers[name];
    return elem;
}

function OpenWindow(query, w, h, scroll) {
    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;

    winprops = 'resizable=1, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w';
    if (scroll) winprops += ',scrollbars=1';
    var f = window.open(query, "_blank", winprops);
}